package com.junsi.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.junsi.bean.Notice;
import com.junsi.mapper.NoticeMapper;
import com.junsi.service.NoticeSerivce;

/**
 * 公告Service接口实现类
 *
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class NoticeSerivceImpl implements NoticeSerivce {
	
	@Autowired
	private NoticeMapper noticeMapper;
	
	@Override
	/**
	 * 根据id查询
	 */
	public Notice findById(Integer id) {		
		Notice notice = noticeMapper.findById(id);
		return notice;
	}

	@Override
	/**
	 * 查询所有
	 */
	public List<Notice> findByAll() {	
		List<Notice> list = noticeMapper.findByAll();
		return list;
	}

	
	@Override
	/**
	 * 新增
	 */
	public boolean save(Notice notice) {
		int i = noticeMapper.save(notice);
		if(i == 1){
			return true;
		}
		return false;
	}

	@Override
	/**
	 * 修改
	 */
	public boolean update(Notice notice) {
		int i = noticeMapper.update(notice);
		if(i == 1){
			return true;
		}
		return false;
	}

	@Override
	/**
	 * 根据id删除
	 */
	public boolean delete(Integer id) {
		int i = noticeMapper.delete(id);
		if(i == 1){
			return true;
		}
		return false;
	}

	@Override
	/**
	 * 分页查询所有公告
	 */
	public List<Notice> pageFind(Integer endIndex, Integer startIndex) {
		if (endIndex == null) {
			return null;
		}
		if (startIndex == null) {
			return null;
		}
		return noticeMapper.pageFind(endIndex, startIndex);
	}



	@Override
	/**
	 * 查询所有公告的记录条数
	 */
	public Integer findByNumber() {
		return noticeMapper.findByNumber();
	}

	@Override
	/**
	 * 批量删除
	 */
	public boolean deletes(String ids) {
		int i = noticeMapper.deletes(ids);
		if (i == 1) {
			return true;
		}
		return false;
	}

	@Override
	/**
	 * 根据发布时间查询公告信息
	 */
	public List<Notice> findByDate(Date notice_releaseDate) {
		List<Notice> list = noticeMapper.findByDate(notice_releaseDate);
		return list;
	}

}
